home *** CD-ROM | disk | FTP | other *** search
- UNIT Menu;
-
- {+----------------------------------------------------------------------------+
- | |
- | HodgePodge: An example Apple IIGS Desktop application |
- | |
- | Written in 65816 assembler and APW C by the Apple IIGS Tools Team |
- | Translated to TML Pascal by TML Systems, Inc. |
- | Modified by Ben Koning for "Programmer's Introduction to the Apple IIGS" |
- | |
- | Copyright (c) 1986-87 by Apple Computer, Inc. |
- | Copyright (c) 1987 by TML Systems, Inc. |
- | |
- | -------------------------------- |
- | |
- | Pascal UNIT "MENU.PAS" : Menu bar setup and menu item handling |
- | |
- +----------------------------------------------------------------------------+}
-
-
-
- INTERFACE
-
- USES
- HPIntfData, {HodgePodge Apple IIGS Toolbox Interface Units}
- HPIntfProc,
- HPIntfPdos,
-
- Globals, {HodgePodge Code Units}
- Dialog,
- Font,
- Paint,
- Window,
- Print;
-
-
-
- procedure DoMenu; {Execute a menu item}
- procedure SetUpMenus; {Install menus and redraw menu bar}
-
-
-
-
-
- IMPLEMENTATION
-
-
-
- procedure AddToMenu;
-
- {Private routine to add a new window item to the "Windows" menu after a
- new window has been drawn. Increments the variable WIndex, a count of
- the number of windows currently open.}
-
- var theWindow : GrafPortPtr;
- myDataHandle : WindDataH;
-
- begin {of AddToMenu}
- theWindow := FrontWindow;
- WindowList [WIndex] := theWindow;
-
- myDataHandle := WindDataH (GetWRefCon (theWindow));
-
- InsertMItem (@myDataHandle^^.menuStr [1],$FFFF,WindowsMenuID);
-
- if WIndex = 0 then begin {This is the first window}
- DeleteMItem (NoWindowsItem); {Remove the "filler" item}
- SetMenuFlag ($FF7F,WindowsMenuID); {Highlight the menu}
- DrawMenuBar;
- end;
-
- CalcMenuSize (0,0,WindowsMenuID);
- Inc (WIndex);
- end; {of AddToMenu}
-
-
-
- procedure DoOpenItem;
-
- {Private routine which is called when the "Open..." item from the "File"
- menu OR the "Display Font..." item from the "Fonts" menu is selected
- (OpenWindow will determine which one it was). If too many windows are
- already open, then a dialog is displayed.}
-
- begin {of DoOpenItem}
- if WIndex < LastWind then
- if OpenWindow then
- AddtoMenu
- else
- else
- ManyWindDialog;
- end; {of DoOpenItem}
-
-
-
- procedure DoQuitItem;
-
- {Private routine to set Done flag if the "Quit" item was selected}
-
- begin {of DoQuitItem}
- Done := true;
- end; {of DoQuitItem}
-
-
-
- procedure DoWindow (itemNum: integer);
-
- {Private routine which brings a specific window to the front of the
- desktop, in response to a selection from the "Windows" menu.}
-
- var theWindow: GrafPortPtr;
-
- begin {of DoWindow}
- theWindow := WindowList [itemNum - FirstWindItem];
- SelectWindow (theWindow);
- ShowWindow (theWindow);
- end; {of DoWindow}
-
-
-
- procedure DoMenu;
-
- {Procedure to handle all menu selections. Examines the Event.TaskData
- menu item ID word from TaskMaster (from Event Manager) and calls the
- appropriate routine. While the routine is running the menu title is
- still highlighted. After the routine returns, we unhilight the
- menu title.}
-
- var menuNum : integer;
- itemNum : integer;
-
- begin {of DoMenu}
-
- menuNum := HiWord (Event.wmTaskData);
- itemNum := LoWord (Event.wmTaskData);
-
- case itemNum of
- AboutItem : DoAboutItem;
- OpenItem : DoOpenItem;
- CloseItem : DoCloseItem;
- SaveAsItem : DoSaveItem;
- ChoosePItem : DoChooserItem;
- PageSetItem : DoSetupItem;
- PrintItem : DoPrintItem;
- QuitItem : DoQuitItem;
- UndoItem : ;
- CutItem : ;
- CopyItem : ;
- PasteItem : ;
- ClearItem : ;
- FontItem : DoOpenItem;
- MonoItem : DoSetMono;
- otherwise
- DoWindow (itemNum);
- end;
-
- HiliteMenu (false,menuNum); {Unhighlight the menu title}
-
- end; {of DoMenu}
-
-
-
- procedure SetUpMenus;
-
- {Procedure to install our menu titles and their items in the system menu
- bar and to redraw it so we can see them.}
-
- var Height : integer;
-
- begin {of SetUpMenus}
- SetMTitleStart(10); {Set Starting position of menu}
-
- InsertMenu (NewMenu (@FontMenuStr [1]),0); {Fonts Menu }
- InsertMenu (NewMenu (@WindowMenuStr [1]),0); {Window Menu }
- InsertMenu (NewMenu (@EditMenuStr [1]),0); {Edit Menu }
- InsertMenu (NewMenu (@FileMenuStr [1]),0); {File Menu }
- InsertMenu (NewMenu (@AppleMenuStr [1]),0); {Apple Menu }
-
- FixAppleMenu (AppleMenuID); {Add DAs to apple menu }
- Height := FixMenuBar; {Set sizes of menus }
- DrawMenuBar; {...and draw the menu bar!}
- end; {of SetUpMenus}
-
-
-
- END.
-